import 'package:flutter/material.dart';
import 'package:cool_alert/cool_alert.dart';

class Example_04 extends StatefulWidget {
  const Example_04({super.key});

  @override
  State<Example_04> createState() => _Example_04State();
}

class _Example_04State extends State<Example_04> {

  List<String> questions = [
    'what are you doing?',
    'what\'s your name?',
    'where are you from?',
    'How much are the vegetables?'
  ];

  List<bool> answer = [
    true,
    false,
    true,
    false
  ];

  int count = 0;

  List<Icon> user = [];

  void judgeUserCap(bool param) {
    if(param == answer[count]) {
      setState(() {
        if(count < questions.length && user.length < questions.length) {
          user.add(Icon( Icons.check, color: Colors.green ));
          count < 3? count++ : null;
        }
      });
    }else {
      CoolAlert.show(
        context: context,
        type: CoolAlertType.error,
        text: "Your transaction was error!",
      );
    }

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: AppBar(
        title: Text('问卷调查'),
        backgroundColor: Colors.yellow,
      ),
      body: SafeArea(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Expanded(
                child: Center(
                  child: Container(
                    child: Text(
                      questions[count],
                      style: TextStyle(
                        color: Colors.white
                      )
                    )
                  ),
                )
            ),
            ElevatedButton(
              onPressed: () {
                judgeUserCap(true);
              },
              child: Text(
                style: TextStyle(
                    fontSize: 20.0,
                    fontWeight: FontWeight.bold
                ),
                'True',
              ),
              style: ElevatedButton.styleFrom(
                disabledBackgroundColor: Colors.white,
                padding: EdgeInsets.symmetric(vertical: 15.0, horizontal: 6.0),
                backgroundColor: Colors.green[400],
                shape: RoundedRectangleBorder(borderRadius: BorderRadius.zero),
              ),
            ),
            SizedBox(height: 6.0,),
            ElevatedButton(
              onPressed: () {
                judgeUserCap(false);
              },
              child: Text(
                  'False',
                  style: TextStyle(
                      fontSize: 20.0,
                      fontWeight: FontWeight.bold
                  ),
              ),
              style: ElevatedButton.styleFrom(
                padding: EdgeInsets.symmetric(vertical: 15.0, horizontal: 6.0),
                backgroundColor: Colors.red[400],
                shape: RoundedRectangleBorder(borderRadius: BorderRadius.zero),
              )
            ),
            Row(
              children: user
            )
          ],
        )
      )
    );
  }
}
